package com.yanchangapp.ui.presenter;

import com.yanchangapp.base.HeadApiRetrofit;
import com.yanchangapp.commom.AppConstant;
import com.yanchangapp.model.response.MgDailyListResponse;
import com.yanchangapp.ui.view.MgDailyListAtView;
import com.zxl.baselib.ui.base.BaseActivity;
import com.zxl.baselib.ui.base.BaseObserver;
import com.zxl.baselib.ui.base.BasePresenter;
import com.zxl.baselib.ui.base.ExceptionHandle;
import com.zxl.baselib.util.NetUtils;

import io.reactivex.Scheduler;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by apple on 2019-07-31.
 * description: 我的管理 - 今日计划 - 我的计划列表P层
 */
public class MgDailyListAtPresenter extends BasePresenter<MgDailyListAtView> {

    public MgDailyListAtPresenter(BaseActivity context) {
        super(context);
    }

    public void queryPlanLists(){
        if (!NetUtils.isConnectedAndToast(mContext)){
            if (getView() != null){
                // 回调失败逻辑...
                getView().queryMailListsFailure("");
            }
            return;
        }

        HeadApiRetrofit.getInstance().queryDailyPlanLists()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<MgDailyListResponse>() {
                    @Override
                    public void onNext(MgDailyListResponse mgDailyListResponse) {
                        if (mgDailyListResponse.getCode() == AppConstant.REQUEST_SUCCESS){
                            getView().queryMailListsSuccess(mgDailyListResponse.getData().getList());
                        }else {
                            if (getView() != null){
                                getView().queryMailListsFailure(mgDailyListResponse.getMsg());
                            }
                        }
                    }

                    @Override
                    public void onError(ExceptionHandle.ResponseException exception) {
                        if (getView() != null){
                            getView().queryMailListsFailure("获取今日计划列表失败");
                        }
                    }
                });
    }
}
